﻿<classes:MSHPhoneApplicationPage 
    x:Class="WP7Client.UserInterface.Pages.SearchResultPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.WP7"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    xmlns:classes="clr-namespace:WP7Client.Classes"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True" Loaded="MSHPhoneApplicationPage_Loaded">

    <classes:MSHPhoneApplicationPage.Resources>
        <classes:BooleanToInvertedBooleanConverter x:Key="BooleanToInvertedBooleanConverter"/>
        <classes:ObjectToVisibilityConverter x:Key="ObjectToVisibilityConverter"/>
        <classes:DateTimeFormatConverter x:Key="DateTimeFormatConverter"/>
        <classes:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <classes:ObjectWithPrivacyToVisibilityConverter x:Key="ObjectWithPrivacyToVisibilityConverter"/>
        <classes:ObjectWithPrivacyToProfileCommandByPeopleNearbyConverter x:Key="ObjectWithPrivacyToProfileCommandByPeopleNearbyConverter"/>

        <DataTemplate x:Key="SearchResultListItemTemplate">
            <StackPanel>
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu Name="ContextMenuSearchResults" Background="Black" BorderBrush="White" BorderThickness="5">
                        <toolkit:MenuItem Header="Send invitation" Foreground="White" FontSize="35" Command="{Binding DataContext.AddFriendCommand, ElementName=PivotSearchResults}" CommandParameter="{Binding Username}" Visibility="{Binding IsFriend, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=invert}"/>
                        <toolkit:MenuItem Header="View profile" Foreground="White" FontSize="35" Command="{Binding Converter={StaticResource ObjectWithPrivacyToProfileCommandByPeopleNearbyConverter}}" CommandParameter="{Binding Username}" Visibility="{Binding Converter={StaticResource ObjectWithPrivacyToVisibilityConverter}}"/>
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>

                <Button cmd:ButtonBaseExtensions.Command="{Binding Converter={StaticResource ObjectWithPrivacyToProfileCommandByPeopleNearbyConverter}}" cmd:ButtonBaseExtensions.CommandParameter="{Binding Username}" Margin="-5,0,0,-15" BorderThickness="0">
                    <StackPanel Orientation="Horizontal" Background="#FFC7C7C7">
                        <Image Source="/WP7Client;component/Resources/Images/avatar.png" Height="100" Width="100"/>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="10,0,0,-10">
                                <TextBlock Text="{Binding FirstName}" TextWrapping="Wrap" Visibility="{Binding FirstName, Converter={StaticResource ObjectToVisibilityConverter}}" HorizontalAlignment="Left" FontSize="28" Margin="0,0,5,0"/>
                                <TextBlock Text="{Binding SurName}" TextWrapping="Wrap" Visibility="{Binding FirstName, Converter={StaticResource ObjectToVisibilityConverter}}" HorizontalAlignment="Left" FontSize="28" />
                            </StackPanel>
                            <TextBlock Text="{Binding Username}" TextWrapping="Wrap" Visibility="{Binding FirstName, Converter={StaticResource ObjectToVisibilityConverter}, ConverterParameter=invert}"  Style="{StaticResource PhoneTextSubtleStyle}"/>
                            <TextBlock Text="{Binding Status}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}"  />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Last seen at:" TextWrapping="Wrap" HorizontalAlignment="Left"  Style="{StaticResource PhoneTextSubtleStyle}"/>
                                <TextBlock Text="{Binding LastSeenTimestamp, Converter={StaticResource DateTimeFormatConverter}}" TextWrapping="Wrap" HorizontalAlignment="Left"  Style="{StaticResource PhoneTextSubtleStyle}"/>
                            </StackPanel>
                            <StackPanel>
                                <TextBlock Text="{Binding DisplayablePosition}" HorizontalAlignment="Left" Style="{StaticResource PhoneTextSubtleStyle}"/>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </Button>
            </StackPanel>
        </DataTemplate>

    </classes:MSHPhoneApplicationPage.Resources>
    
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <controls:Pivot Name="PivotSearchResults" Title="SEARCH RESULTS" IsEnabled="{Binding Path=Loading, ElementName=PivotSearchResults, Converter={StaticResource BooleanToInvertedBooleanConverter}}" SelectionChanged="PivotSearchResults_SelectionChanged">

        </controls:Pivot>
        <ProgressBar Height="10" Grid.Row="0" VerticalAlignment="Top" IsIndeterminate="{Binding Path=Loading, ElementName=PivotSearchResults}" />
    </Grid>
    
</classes:MSHPhoneApplicationPage>
